home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / disk / cdrom / MusicBox-2.1bi.lha / MusicBox / ShowCD.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-29  |  13.4 KB  |  509 lines

  1. /*
  2.  ##########################################################################
  3.  ####                                                                  ####
  4.  ####                        The MusicBox Project                      ####
  5.  ####                    ============================                  ####
  6.  ####                                                                  ####
  7.  #### ShowCD.c                                                         ####
  8.  ####                                                                  ####
  9.  #### Version 2.1os  --  September 29, 2000                            ####
  10.  ####                                                                  ####
  11.  #### Copyright (C) 1994  Thomas Dreibholz                             ####
  12.  ####               2000  Molbachweg 7                                 ####
  13.  ####                     51674 Wiehl                                  ####
  14.  ####                     Germany                                      ####
  15.  ####                                                                  ####
  16.  ####                     EMail: Dreibholz@bigfoot.com                 ####
  17.  ####                     WWW:   http://www.bigfoot.com/~dreibholz     ####
  18.  ####                                                                  ####
  19.  ##########################################################################
  20. */
  21. /***************************************************************************
  22.  *                                                                         *
  23.  *   This program is free software; you can redistribute it and/or modify  *
  24.  *   it under the terms of the GNU General Public License as published by  *
  25.  *   the Free Software Foundation; either version 2 of the License, or     *
  26.  *   (at your option) any later version.                                   *
  27.  *                                                                         *
  28.  ***************************************************************************/
  29.  
  30. /* ShowCD */
  31.  
  32. #include "MusicBox.h"
  33. #include "MusicBoxLibrary.h"
  34.  
  35. #define VERSION  210
  36. #define VERSTR   "$VER: ShowCD 2.1os (Sep 29 2000) - Copyright (C) 1994-2000 by Thomas Dreibholz"
  37. #define TITEL    "ShowCD - Version 2.1os"
  38.  
  39. #define KatalogLeft   100
  40. #define KatalogTop     20
  41. #define KatalogWidth  440
  42. #define KatalogHeight 205
  43.  
  44. struct IntuitionBase *IntuitionBase;
  45. struct GfxBase       *GfxBase;
  46. struct GadToolsBase  *GadToolsBase;
  47. struct Library       *WorkbenchBase;
  48. struct Library       *MusicBoxBase;
  49. struct Library       *LocaleBase;
  50. struct Library       *DiskfontBase;
  51.  
  52. ULONG IDCMPSignalMask,PortSignalMask;
  53. ULONG WaitSignalMask;
  54. BOOL  USModus;
  55.  
  56. struct Window     *win;
  57. struct RastPort   *rp;
  58. struct VisualInfo *vi;
  59. struct Screen     *scr;
  60. struct Gadget     *GListe;
  61. struct Gadget     *Gadgets[4];
  62. struct Katalog    *Katalog;
  63. struct MsgPort    *AppPort;
  64. struct AppWindow  *AppWin;
  65. struct Remember   *TitelRemember=NULL;
  66. struct Locale     *Locale;
  67. struct Catalog    *Catalog;
  68. struct TextFont   *Font,*TimesFont;
  69.  
  70. extern struct WBStartupMsg *WBenchMsg;
  71. extern struct DiskObject    ShowCD;
  72.  
  73. struct TextAttr TimesAttr=
  74. {
  75.  "times.font",15,FS_NORMAL,FPF_DISKFONT
  76. };
  77.  
  78. struct CNode
  79. {
  80.  struct Node Node;
  81.  UBYTE       Titel[60];
  82. };
  83.  
  84. struct NewGadget   ListeGadget={5,5,430,170,0L,&TimesAttr,1,0,0,0};
  85. struct NewGadget   OkayGadget={5,180,130,18,0L,&TimesAttr,2,0,0,0};
  86. struct NewGadget   ArcGadget={145,180,150,18,0L,&TimesAttr,3,0,0,0};
  87. struct NewGadget   InfoGadget={305,180,130,18,0L,&TimesAttr,4,0,0,0};
  88. struct List        Liste;
  89. struct TagItem     ListeTags[]={GTLV_Labels,&Liste,
  90.                                 GTLV_ReadOnly,TRUE,
  91.                                 TAG_DONE};
  92. struct TagItem     BoolTags[]={GT_Underscore,'_',
  93.                                TAG_DONE};
  94.  
  95. UBYTE *VerStr=VERSTR;
  96.  
  97. void LadeKatalog();
  98. void Gesamtkatalog();
  99. void About();
  100. void Error();
  101. LONG MultiRequest();
  102.  
  103. UBYTE *GS(num,def)
  104.  LONG   num;
  105.  UBYTE *def;
  106. {
  107.  if(Catalog==NULL) return(def);
  108.  return(GetCatalogStr(Catalog,num,def));
  109. }
  110.  
  111. void CloseAll()
  112. {
  113.  if(win) CloseWindow(win);
  114.  if(scr) UnlockPubScreen(NULL,scr);
  115.  if(vi) FreeVisualInfo(vi);
  116.  if(GListe) FreeGadgets(GListe);
  117.  if(Katalog) FreeMem(Katalog,sizeof(struct Katalog));
  118.  if(AppPort) DeletePort(AppPort);
  119.  if(AppWin) RemoveAppWindow(AppWin);
  120.  if(TitelRemember) FreeRemember(TitelRemember);
  121.  if(Font) CloseFont(Font);
  122.  if(LocaleBase)
  123.   {
  124.    if(Catalog) CloseCatalog(Catalog);
  125.    if(Locale) CloseLocale(Locale);
  126.    CloseLibrary(LocaleBase);
  127.   }
  128.  EntferneIcon();
  129.  if(MusicBoxBase) CloseLibrary(MusicBoxBase);
  130.  if(DiskfontBase) CloseLibrary(DiskfontBase);
  131.  if(GadToolsBase) CloseLibrary(GadToolsBase);
  132.  if(WorkbenchBase) CloseLibrary(WorkbenchBase);
  133.  if(IntuitionBase) CloseLibrary(IntuitionBase);
  134.  if(GfxBase) CloseLibrary(GfxBase);
  135.  exit(0);
  136. }
  137.  
  138. void OpenAll()
  139. {
  140.  REGISTER BOOL     bool;
  141.  struct TagItem    tag[10];
  142.  struct Gadget    *g;
  143.  
  144.  if(USModus==FALSE)
  145.   {
  146.    LocaleBase=OpenLibrary("locale.library",38L);
  147.    if(LocaleBase!=NULL)
  148.     {
  149.      Locale=OpenLocale(NULL);
  150.      if(Locale!=NULL)
  151.        Catalog=OpenCatalogA(Locale,"musicbox.catalog",NULL);
  152.     }
  153.   }
  154.  OkayGadget.ng_GadgetText=GS(57,"_Close");
  155.  ArcGadget.ng_GadgetText=GS(58,"_Archive...");
  156.  InfoGadget.ng_GadgetText=GS(80,"A_bout...");
  157.  IntuitionBase=OpenLibrary("intuition.library",37L);
  158.  GfxBase=OpenLibrary("graphics.library",37L);
  159.  if((IntuitionBase==NULL)||(GfxBase==NULL))
  160.   {
  161.    puts(GS(1,"This program requires Kickstart 2.0, V37!"));
  162.    CloseAll();
  163.   }
  164.  GadToolsBase=OpenLibrary("gadtools.library",37L);
  165.  if(GadToolsBase==NULL)
  166.   {
  167.    Error(GS(4,"Unable to open gadtools.library!"));
  168.    CloseAll();
  169.   }
  170.  WorkbenchBase=OpenLibrary("workbench.library",37L);
  171.  if(WorkbenchBase==NULL)
  172.   {
  173.    Error(GS(3,"Unable to open workbench.library"));
  174.    CloseAll();
  175.   }
  176.  DiskfontBase=OpenLibrary("diskfont.library",0L);
  177.  if(DiskfontBase==NULL)
  178.   {
  179.    Error(GS(5,"Unable to open diskfont.library"));
  180.    CloseAll();
  181.   }
  182.  MusicBoxBase=OpenLibrary("musicbox.library",0L);
  183.  if(MusicBoxBase==NULL)
  184.   {
  185.    Error(GS(55,"Unable to open musicbox.library"));
  186.    CloseAll();
  187.   }
  188.  if((LibVersionCheck(VERSION))==0)
  189.    CloseAll();
  190.  Katalog=AllocMem(sizeof(struct Katalog),MEMF_ANY);
  191.  bool=InitIcon();
  192.  if((Katalog==NULL)||(bool==FALSE))
  193.   {
  194.    Error(GS(6,"Not enough memory!"));
  195.    CloseAll();
  196.   }
  197.  AppPort=CreatePort(0L,0L);
  198.  if(AppPort==NULL)
  199.   {
  200.    Error(GS(12,"Unable to create message port"));
  201.    CloseAll();
  202.   }
  203.  Katalog->DiscID=0xFFFFFFFF;
  204.  scr=LockPubScreen(NULL);
  205.  if(scr==NULL)
  206.   {
  207.    Error(GS(26,"Unable to lock public screen!"));
  208.    CloseAll();
  209.   }
  210.  if(scr->Height<300)
  211.   {
  212.    TimesAttr.ta_Name="topaz.font";
  213.    TimesAttr.ta_YSize=9;
  214.   }
  215.  Font=OpenDiskFont(&TimesAttr);
  216.  vi=GetVisualInfoA(scr,NULL);
  217.  if(vi==NULL)
  218.   {
  219.    Error(GS(30,"Unable to get VisualInfo!"));
  220.    CloseAll();
  221.   }
  222.  NewList(&Liste);
  223.  ListeGadget.ng_VisualInfo=vi;
  224.  OkayGadget.ng_VisualInfo=vi;
  225.  ArcGadget.ng_VisualInfo=vi;
  226.  InfoGadget.ng_VisualInfo=vi;
  227.  g=CreateContext(&GListe);
  228.  if(g==NULL)
  229.   {
  230.    Error(GS(31,"Unable to create gadgets!"));
  231.    CloseAll();
  232.   }
  233.  Gadgets[0]=g=CreateGadgetA(LISTVIEW_KIND,g,&ListeGadget,&ListeTags);
  234.  Gadgets[1]=g=CreateGadgetA(BUTTON_KIND,g,&OkayGadget,&BoolTags);
  235.  Gadgets[2]=g=CreateGadgetA(BUTTON_KIND,g,&ArcGadget,&BoolTags);
  236.  Gadgets[3]=g=CreateGadgetA(BUTTON_KIND,g,&InfoGadget,&BoolTags);
  237.  if((Gadgets[0]==0)||(Gadgets[1]==NULL)||(Gadgets[2]==NULL)||(Gadgets[3]==NULL))
  238.   {
  239.    Error(GS(31,"Unable to create gadgets!"));
  240.    CloseAll();
  241.   }
  242.  tag[0].ti_Tag=WA_Left;
  243.  tag[0].ti_Data=KatalogLeft;
  244.  tag[1].ti_Tag=WA_Top;
  245.  tag[1].ti_Data=KatalogTop;
  246.  tag[2].ti_Tag=WA_InnerWidth;
  247.  tag[2].ti_Data=KatalogWidth;
  248.  tag[3].ti_Tag=WA_InnerHeight;
  249.  tag[3].ti_Data=KatalogHeight;
  250.  tag[4].ti_Tag=WA_IDCMP;
  251.  tag[4].ti_Data=CLOSEWINDOW|LISTVIEWIDCMP|IDCMP_GADGETUP|IDCMP_VANILLAKEY;
  252.  tag[5].ti_Tag=WA_Flags;
  253.  tag[5].ti_Data=ACTIVATE|WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|SMART_REFRESH|GIMMEZEROZERO;
  254.  tag[6].ti_Tag=WA_Gadgets;
  255.  tag[6].ti_Data=GListe;
  256.  tag[7].ti_Tag=WA_Title;
  257.  tag[7].ti_Data=TITEL;
  258.  tag[8].ti_Tag=WA_PubScreen;
  259.  tag[8].ti_Data=scr;
  260.  tag[9].ti_Tag=TAG_DONE;
  261.  win=OpenWindowTagList(NULL,&tag);
  262.  if(win==NULL)
  263.   {
  264.    Error(GS(33,"Unable to open window!"));
  265.    CloseAll();
  266.   }
  267.  GTRefreshWindow(win,NULL);
  268.  IDCMPSignalMask=(1L<<win->UserPort->mp_SigBit);
  269.  PortSignalMask=(1L<<AppPort->mp_SigBit);
  270.  WaitSignalMask=IDCMPSignalMask+PortSignalMask;
  271.  AppWin=AddAppWindowA(1,0,win,AppPort,NULL);
  272.  if(AppWin==NULL)
  273.   {
  274.    Error(GS(56,"Unable to init AppWindow!"));
  275.    CloseAll();
  276.   }
  277. }
  278.  
  279. void main(argc,argv)
  280.  long   argc;
  281.  UBYTE *argv[];
  282. {
  283.  REGISTER ULONG                 Class,Signale;
  284.  REGISTER UWORD                 Code;
  285.  register BOOL                  ende;
  286.  register  struct IntuiMessage *msg;
  287.  register struct WBArg         *arg;
  288.  register struct Gadget        *gad;
  289.  register struct AppMessage    *app;
  290.  register struct FileLock      *lock;
  291.  int                            test;
  292.  
  293.  OpenAll();
  294.  
  295.  if(argc>1)
  296.   {
  297.    if(!(strcmp(argv[1],"?")))
  298.     {
  299.      printf("USAGE: %s [catalog file] [-u|US]\n",argv[0]);
  300.      exit(0);
  301.     }
  302.    else
  303.      LadeKatalog(argv[1]);
  304.    for(test=1;test<argc;test++)
  305.     {
  306.      if(!(strcmp(argv[test],"-u"))) USModus=TRUE;
  307.      if(!(strcmp(argv[test],"US"))) USModus=TRUE;
  308.     }
  309.   }
  310.  
  311.  else if(WBenchMsg!=NULL)
  312.    if(WBenchMsg->sm_NumArgs>1)
  313.     {
  314.      arg=(ULONG)WBenchMsg->sm_ArgList+(ULONG)sizeof(struct WBArg);
  315.      lock=CurrentDir(arg->wa_Lock);
  316.      LadeKatalog(arg->wa_Name);
  317.      CurrentDir(lock);
  318.     }
  319.  ende=FALSE;
  320.  do
  321.   {
  322.    Signale=Wait(WaitSignalMask);
  323.    if(Signale & IDCMPSignalMask)
  324.     {
  325.      msg=GTGetIMsg(win->UserPort);
  326.      while(msg!=NULL)
  327.       {
  328.        Class=msg->Class;
  329.        Code=msg->Code;
  330.        gad=msg->IAddress;
  331.        GTReplyIMsg(msg);
  332.        switch(Class)
  333.         {
  334.          case CLOSEWINDOW:
  335.            ende=TRUE;
  336.           break;
  337.          case GADGETUP:
  338.            switch(gad->GadgetID)
  339.             {
  340.              case 2:
  341.                ende=TRUE;
  342.               break;
  343.              case 3:
  344.                Gesamtkatalog();
  345.               break;
  346.              case 4:
  347.                About();
  348.               break;
  349.             }
  350.           break;
  351.          case VANILLAKEY:
  352.            switch((UBYTE)toupper(Code))
  353.             {
  354.              case 'C':
  355.              case 'S':
  356.                ende=TRUE;
  357.               break;
  358.              case 'B':
  359.                About();
  360.              case 'A':
  361.                Gesamtkatalog();
  362.               break;
  363.             }
  364.           break;
  365.         }
  366.        msg=GTGetIMsg(win->UserPort);
  367.       }
  368.     }
  369.    if(Signale & PortSignalMask)
  370.     {
  371.      app=GetMsg(AppPort);
  372.      while(app!=NULL)
  373.       {
  374.        if(app->am_Type=MTYPE_APPWINDOW)
  375.         {
  376.          arg=app->am_ArgList;
  377.          lock=CurrentDir(arg->wa_Lock);
  378.          LadeKatalog(arg->wa_Name);
  379.          CurrentDir(lock);
  380.         }
  381.        ReplyMsg(app);
  382.        app=GetMsg(AppPort);
  383.       }
  384.     }
  385.   } while(ende==FALSE);
  386.  CloseAll();
  387. }
  388.  
  389. void LadeKatalog(name)
  390.  UBYTE *name;
  391. {
  392.  struct TagItem              tag[2];
  393.  register struct FileHandle *fh;
  394.  register struct CNode      *node;
  395.  register int                i;
  396.  
  397.  SleepPointer(win);
  398.  fh=Open(name,MODE_OLDFILE);
  399.  if(fh!=NULL)
  400.   {
  401.    Katalog->Anzahl=99;
  402.    Read(fh,Katalog,KSIZE(Katalog));
  403.    Close(fh);
  404.    if((strncmp(&Katalog->ID,"DISC",4)))
  405.     {
  406.      Katalog->DiscID=0xFFFFFFFF;
  407.      ClearPointer(win);
  408.      return;
  409.     }
  410.    NewList(&Liste);
  411.    if(TitelRemember)
  412.      FreeRemember(TitelRemember,TRUE);
  413.    TitelRemember=NULL;
  414.    node=AllocRemember(&TitelRemember,sizeof(struct CNode),MEMF_ANY|MEMF_CLEAR);
  415.    if(node==NULL)
  416.     {
  417.      Error(GS(6,"Not enough memory!"));
  418.      CloseAll();
  419.     }
  420.    node->Node.ln_Name=&node->Titel;
  421.    sprintf(&node->Titel,"%s:",&Katalog->CDName);
  422.    AddTail(&Liste,node);
  423.    for(i=0;i<Katalog->Anzahl;i++)
  424.     {
  425.      node=AllocRemember(&TitelRemember,sizeof(struct CNode),MEMF_ANY|MEMF_CLEAR);
  426.      if(node==NULL)
  427.       {
  428.        Error(GS(6,"Not enough memory!"));
  429.        CloseAll();
  430.       }
  431.      node->Node.ln_Name=&node->Titel;
  432.      if(scr->Height>299)
  433.        sprintf(&node->Titel,"%02d  %s",i+1,&Katalog->KE[i].Titel);
  434.      else
  435.        sprintf(&node->Titel,"%02d %s",i+1,&Katalog->KE[i].Titel);
  436.      AddTail(&Liste,node);
  437.     }
  438.    tag[0].ti_Tag=GTLV_Labels;
  439.    tag[0].ti_Data=&Liste;
  440.    tag[1].ti_Tag=TAG_DONE;
  441.    GTSetGadgetAttrsA(Gadgets[0],win,NULL,&tag);
  442.   }
  443.  ClearPointer(win);
  444. }
  445.  
  446. void Gesamtkatalog()
  447. {
  448.  SleepPointer(win);
  449.  OpenArchive(Katalog->DiscID,0,0);
  450.  ClearPointer(win);
  451. }
  452.  
  453. LONG MultiRequest(titel,text,gads)
  454.  UBYTE *titel,*text,*gads;
  455. {
  456.  struct EasyStruct easy;
  457.  
  458.  easy.es_StructSize=sizeof(struct EasyStruct);
  459.  easy.es_Flags=0;
  460.  easy.es_Title=titel;
  461.  easy.es_TextFormat=text;
  462.  easy.es_GadgetFormat=gads;
  463.  return(EasyRequestArgs(NULL,&easy,0L,0L));
  464. }
  465.  
  466. void Error(text)
  467. {
  468.  MultiRequest(GS(15,"Music Box - Error!"),text,GS(16,"Abort"));
  469. }
  470.  
  471. void About()
  472. {
  473.  UBYTE             tex[12];
  474.  struct InfoStruct info;
  475.  
  476.  sprintf(&tex,"#%08lx",Katalog->DiscID);
  477.  info.Title=GS(81,"ShowCD - Information");
  478.  info.ProgName=TITEL;
  479.  info.Icon=&ShowCD;
  480.  if(scr->Height>270) info.LowRes=FALSE; else info.LowRes=TRUE;
  481.  info.Text[0].LeftEdge=95;
  482.  info.Text[0].TopEdge=95;
  483.  info.Text[0].Flags=ISTF_LEFT;
  484.  info.Text[0].Text=GS(18,"Current CD:");
  485.  info.Text[1].LeftEdge=95;
  486.  info.Text[1].TopEdge=110;
  487.  info.Text[1].Flags=ISTF_LEFT;
  488.  info.Text[1].Text=GS(19,"ID number:");
  489.  if(Katalog->DiscID!=0xFFFFFFFF)
  490.   {
  491.    info.Text[2].LeftEdge=180;
  492.    info.Text[2].TopEdge=95;
  493.    info.Text[2].Flags=ISTF_LEFT;
  494.    info.Text[2].Text=&Katalog->CDName;
  495.    info.Text[3].LeftEdge=180;
  496.    info.Text[3].TopEdge=110;
  497.    info.Text[3].Flags=ISTF_LEFT;
  498.    info.Text[3].Text=&tex;
  499.    info.Text[4].LeftEdge=0;
  500.   }
  501.  else
  502.    info.Text[2].LeftEdge=0;
  503.  info.RegInfo = "";
  504.  SleepPointer(win);
  505.  InformationA(&info);
  506.  ClearPointer(win);
  507. }
  508.  
  509.